home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / FWExcLib / Include / FWExcept.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-21  |  3.2 KB  |  109 lines  |  [TEXT/MPS ]

  1. #ifndef FWEXCEPT_H
  2. #define FWEXCEPT_H
  3. //========================================================================================
  4. //
  5. //    File:                FWExcept.h
  6. //    Release Version:    $ 1.0d1 $
  7. //
  8. //    Creation Date:        3/28/94
  9. //
  10. //    Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  11. //
  12. //========================================================================================
  13.  
  14. #ifndef   FWCLAINF_H
  15. #include "FWClaInf.h"
  16. #endif
  17.  
  18. #ifndef FWPRIDEB_H
  19. #include "FWPriDeb.h"
  20. #endif
  21.  
  22. //========================================================================================
  23. // Exception classes definition and implementation macros
  24. //========================================================================================
  25.  
  26. #define _FW_EXCEPTION_DEFINE(name) \
  27. public: \
  28.     FW_DECLARE_CLASS
  29.  
  30. #define _FW_EXCEPTION_IMPLEMENT_ROOT(name) \
  31.     FW_DEFINE_CLASS_M0(name)
  32.  
  33. #define _FW_EXCEPTION_IMPLEMENT(name, ancestor) \
  34.     FW_DEFINE_CLASS_M1(name, ancestor)
  35.  
  36. //========================================================================================
  37. // CLASS _FW_CException
  38. //========================================================================================
  39.  
  40. class _FW_CException
  41. {
  42. public:
  43.     virtual ~_FW_CException();
  44.     _FW_CException();
  45.     
  46.     int __IsKindOf(FW_ClassReference  aClass);
  47.         // Returns 1 if this object is a kind of aClass, i.e. same or subclass of aClass.
  48.         
  49.     size_t GetSize() const;
  50.         // Returns the size of this object, using info from its metaclass
  51.         // This method is not virtual, but will work correctly since PrivVirtualGetClassInfo is virtual.
  52.     
  53.     virtual void Copy(void *p, size_t maxObjectSize) const;
  54.         // Copies this object.  This method does a bitwise copy, but subclasses
  55.         //   must override to perform a deep copy.
  56.  
  57.     void Delete();
  58.         // Calls the virtual destructor, but does not attept to delete storage.
  59.  
  60.     const char* GetClassName() const;
  61.         // Returns the class name of this object, as a string.
  62.         // This method is not virtual, but will work correctly since PrivVirtualGetClassInfo is virtual.
  63.  
  64. #ifdef FW_DEBUG
  65.     short    fIsValid;
  66. #endif
  67.  
  68.     _FW_EXCEPTION_DEFINE(_FW_CException)
  69.  
  70. public:
  71.     // these are provided to mask a bug in Borland C++ (it calls delete when
  72.     //    you just want to call the dtor, explicitly)
  73.     void* operator new(size_t size);
  74.     void operator delete(void* memory);
  75. };
  76.  
  77. //========================================================================================
  78. // CLASS _FW_CException inline functions
  79. //========================================================================================
  80.  
  81. inline size_t _FW_CException::GetSize() const
  82. {
  83.     FW_PRIV_ASSERT(fIsValid==1);
  84.     return PrivVirtualGetClassInfo()->GetInstanceSize();
  85. }
  86.  
  87. inline const char* _FW_CException::GetClassName() const
  88. {
  89.     FW_PRIV_ASSERT(fIsValid==1);
  90.     return PrivVirtualGetClassInfo()->GetClassName();
  91. }
  92.  
  93. inline void _FW_CException::Delete()
  94. {
  95.     FW_PRIV_ASSERT(fIsValid==1);
  96. #ifdef _MPWCFRONT
  97.     // MPW CFront is not supported with this version of the code
  98.     FW_PRIV_ASSERT(FALSE);
  99.     // CFront is bizarre.  It won't allow the unscoped destructor name, but the scoped 
  100.     // name is dispatched virtually, even though ARM says scoped names are never virtual.
  101.     this->_FW_CException::~_FW_CException();
  102. #else
  103.     this->~_FW_CException();    // Virtual dispatch to object's destructor
  104. #endif
  105.     FW_PRIV_ASSERT(fIsValid==0);
  106. }
  107.  
  108. #endif
  109.